package org.tigr.htc.cmd;

/*
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

import org.apache.log4j.Logger;

/**
 * The <b>Param</b> class represents a Command parameter. A parameter is a 
 * tuple of a type, key, and value.
 *
 */

public class Param {
    static Logger log = Logger.getLogger("org.tigr.htc.cmd.Param");
    private String key;
    private String value;
    private ParamType type;
    private int id;
    private Command cmd;

    /**
     * Creates a new uninitialized <code>Param</code> instance.
     * no-args, values to be set later. Needed for Castor and serialization.
     */
    public Param() { }

    /**
     * Creates a new <code>Param</code> instance.
     * key defaults to null, type defaults to PARAM
     *
     * @param p_value a <code>String</code> value
     */
    public Param(String p_value) {
	key = null;
	value = p_value;
	type = ParamType.PARAM;
    }

    /**
     * Creates a new <code>Param</code> instance.
     * key defaults to null
     *
     * @param p_value a <code>String</code> value
     * @param p_type a <code>ParamType</code> value
     */
    public Param(String p_value, ParamType p_type) {
	key = null;
	value = p_value;
	type = p_type;
    }

    /**
     * Creates a new <code>Param</code> instance.
     * type defaults to PARAM.
     *
     * @param p_key a <code>String</code> value
     * @param p_value a <code>String</code> value
     */
    public Param(String p_key, String p_value) {
	key = p_key;
	value = p_value;
	type = ParamType.PARAM;
    }

    /**
     * Creates a new <code>Param</code> instance.
     *
     * @param p_key a <code>String</code> value
     * @param p_value a <code>String</code> value
     * @param p_type a <code>ParamType</code> value
     */
    public Param(String p_key, String p_value, ParamType p_type) {
	key = p_key;
	value = p_value;
	type = p_type;
    }

    public Command getCommand() {
	log.debug(" param get command ->" + cmd.getID());
	return this.cmd;
    }
    
    public void setCommand(Command p_cmd) {
	log.debug("param set command " + p_cmd.getID());
	this.cmd = p_cmd;
    }

    /**
     * <code>getID</code> get command ID.
     * 
     * @return an <code>long</code> command id
     */
    public int getID() {
	log.debug(" param get id ->" + id);
	return this.id;
    }
    
    /**
     * <code>setID</code> set command ID.
     * 
     * @param p_id
     *            an <code>long</code> command id
     */
    public void setID(int p_id) {
	log.debug("param set id " + p_id);
	this.id = p_id;
    }

    /**
     * <code>getKey</code> get the parameter key
     *
     * @return the parameter key
     */
    public String getKey() {
	log.debug("method Param.getKey return" + key);
	return key;
    }

    /**
     * <code>setKey</code> set the paramter key
     *
     * @param p_key a <code>String</code> value
     */
    public void setKey(String p_key) {
	log.debug("method Param.setKey return" + p_key);
	key = p_key;
    }

    /**
     * <code>getValue</code> get the parameter value.
     *
     * @return a <code>String</code> value
     */
    public String getValue() {
	log.debug("method Param.getValue return " + value);
	return value;
    }

    /**
     * Describe <code>setValue</code> method here.
     *
     * @param p_value a <code>String</code> value
     */
    public void setValue(String p_value) {
	log.debug("method Parm.setValue " + p_value);
	value = p_value;
    }


    /**
     * <code>getTypeAsString</code> method for xml marshalling
     *
     * @return a <code>String</code> value
     */
    public String getTypeAsString() {
	return type.toString();
    }

    /**
     * Get the Type value.
     * @return the Type value.
     */
    public ParamType getType() {
	return type;
    }

    /**
     * Set the Type value.
     * @param p_Type The new Type value.
     */
    public void setType(ParamType p_type) {
	this.type = p_type;
    }


    /**
     * Set the Type value.
     * @param p_Type The new Type value.
     */
    public void setType(String p_type) {
	this.type = ParamType.getType(p_type);
    }
    
    /**
     * <code>toString</code> prints out xml representation of Param
     * using CommandHelper.
     *
     * @return a <code>String</code> value
     */
    public String toString() {
	return CommandHelper.getInstance().marshal(this);
    }

    
    public String toStringNormal () {
        return "Type: " + type + " key: " + key + " value: " + value;
    }
}
